package com.example.config;

import com.mysql.cj.jdbc.MysqlDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

public class JdbcConfig {
    @Value("${jdbc.driver}")
    private String driver;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Bean
    public DataSource dataSource(){
        DriverManagerDataSource mysqlDataSource=new DriverManagerDataSource();
        mysqlDataSource.setDriverClassName(driver);
        mysqlDataSource.setUrl(url);
        mysqlDataSource.setUsername(username);
        mysqlDataSource.setPassword(password);
        return mysqlDataSource;
    }
}
